package com.suse.util;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//登录拦截器
public class LoginInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入到了拦截器");
        //获取登录信息
        Object obj = request.getSession().getAttribute("name");
        if (obj == null) {
            //未登录，回到登录页面
            request.getRequestDispatcher("/login").forward(request, response);
            return false;
        }
        return true;
    }
}
